"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Client extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      Client.hasOne(models.Project, {
        foreignKey: "client_id",
        // onDelete:'SET DEFAULT'
      });
      Client.hasMany(models.Opportunity, {
        foreignKey: "client_id",
        // onDelete:'SET DEFAULT'
      });
      Client.hasMany(models.Inventory, {
        foreignKey: "client_id",
        // onDelete:'SET DEFAULT'
      });
      Client.hasMany(models.Receipt, {
        foreignKey: "client_id",
        // onDelete:'SET DEFAULT'
      });
      Client.hasMany(models.Service, {
        foreignKey: "client_id",
        // onDelete:'SET DEFAULT'
      });
      // Client.belongsTo(models.Staff,{
      //   foreignKey:'checker_id',
      //   as:'checker',
      //   unique:false
      // })
      // define association here
    }
  }
  Client.init(
    {
      client_name: DataTypes.STRING,
      client_address: DataTypes.STRING,
      client_website: DataTypes.STRING,
      person_name: DataTypes.STRING, //客户对接人信息，是伪JSON数组的形式
      // person_phone: {
      //   type:DataTypes.STRING,

      // },
      // person_email: {
      //   type:DataTypes.STRING,

      // },
      // person_position: DataTypes.STRING, //客户对接人职位
      client_status: {
        type: DataTypes.STRING,
        defaultValue: "待审核",
      }, //审核状态
      check_sug: DataTypes.STRING,
      checker_id: DataTypes.INTEGER, //审核人id
    },
    {
      sequelize,
      modelName: "Client",
      tableName: "clients",
    }
  );
  return Client;
};
